<?php

App::uses('AdminAppController', 'Admin.Controller');
App::uses('AppController', 'Controller');

class SettingsController extends AdminAppController {

    var $helpers = array('Form');

    function index() {
        $this->paginate = array(
            'limit' => 25,
            'order' => array('Setting.id' => 'desc')
        );

        // we are using the 'Admin' model
        $rows = $this->paginate('Setting');

        // pass the value to our view.ctp
        $this->set('rows', $rows);
    }

    function edit($id = null) {
        if (!$id) {
            throw new NotFoundException(__('Invalid post'));
        }
        $post = $this->Setting->findById($id);
        if (!$post) {
            throw new NotFoundException(__('Invalid post'));
        }

        if ($this->request->is(array('post', 'put'))) {
            $this->Setting->id = $id;            

            if ($this->Setting->save($this->request->data)) {
                $this->Session->setFlash('Setting has been updated.!', 'default', array(), 'good');
                return $this->redirect(array('action' => 'index'));
            }
            $this->Session->setFlash('Unable to update setting.!', 'default', array(), 'bad');
        }

        if (!$this->request->data) {
            $this->request->data = $post;
        }
    }
}
